/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package e.z.blog.back.setup;

import e.z.blog.back.bean.base.Essay;
import e.z.blog.back.bean.base.New;
import e.z.blog.back.bean.base.Lan;
import e.z.blog.back.bean.base.Tab;
import e.z.blog.back.bean.base.Tag;
import e.z.blog.back.com.DaoLanApi;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;

/**
 *
 * @author EnzoZhong
 */
public class LanTabEssayTagRemarkSetup implements Setup {

        @Override
        public void init ( NutConfig config ) {

                Ioc ioc = config.getIoc();
                Dao dao = ioc.get( Dao.class , "dao" );
                /*
                 * 建表
                 */
                dao.create( Lan.class , false );
                dao.create( Tab.class , false );
                dao.create( Essay.class , false );
                dao.create( Tag.class , false );
                dao.create( New.class , false );
                /*
                 * 创建默认对象
                 */
                Lan defLan = ioc.get( Lan.class , "defLan" );
                Tab defTab = ioc.get( Tab.class , "defTab" );
                /*
                 * 检查默认值是否存在
                 */
                if ( dao.fetch( Lan.class , defLan.getLanName() ) == null ) {
                        dao.insert( defLan );
                }
                if ( dao.fetch( Tab.class , defTab.getTabName() ) == null ) {
                        dao.insert( defTab );
                }
        }

        @Override
        public void destroy ( NutConfig config ) {
                throw new UnsupportedOperationException( "Not supported yet." );
        }
}
